package com.akkainaction.tool.io.udp.actor.client;

import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import akka.io.UdpConnected;
import akka.io.UdpMessage;

import java.net.InetSocketAddress;

public class UDPClientActor extends UntypedActor {

    @Override
    public void preStart() throws Exception {
        ActorRef udpManager = UdpConnected.get(getContext().system()).getManager();
        udpManager.tell(UdpMessage.bind(getSelf(), new InetSocketAddress("127.0.0.1", 6998)), getSelf());
    }

    @Override
    public void onReceive(Object msg) throws Exception {
        System.out.println(getSelf() + "收到消息:[" + msg + "]");
    }
}
